<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

	<head>
		<title>[%$ESPCMS_SOFT_TITLE%]</title>
		<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
		<link href="[%$ESPCMS_ADMIN_TEMPLATES_URL%]css/espcms_style_font_icon.css" rel="stylesheet" type="text/css" />
		<link href="[%$ESPCMS_ADMIN_TEMPLATES_URL%]css/espcms_style_public.css" rel="stylesheet" type="text/css" />
		<link href="[%$ESPCMS_ADMIN_TEMPLATES_URL%]css/espcms_all.css" rel="stylesheet" type="text/css" />
		<link href="[%$ESPCMS_ADMIN_TEMPLATES_URL%]css/espcms_style_font_icon.css" rel="stylesheet" type="text/css" />
		<link href="[%$ESPCMS_ADMIN_TEMPLATES_URL%]css/espcms_framework.css" rel="stylesheet" type="text/css" />
		<link href="[%$ESPCMS_ADMIN_TEMPLATES_URL%]css/espcms_select.css" rel="stylesheet" type="text/css" />
		<script type="text/javascript" src="[%ESPCMS_ADMIN_URL%]js/jquery.min.js"></script>
		<script type="text/javascript" src="[%ESPCMS_ADMIN_URL%]js/jquery-ui.min.js"></script>
		<script type="text/javascript" src="[%ESPCMS_ADMIN_URL%]js/jquery.cookie.js"></script>
		<script type="text/javascript" src="[%ESPCMS_ADMIN_URL%]js/md5.js"></script>
		<script type="text/javascript" src="[%ESPCMS_ADMIN_URL%]js/json.js"></script>
		<script type="text/javascript" src="[%ESPCMS_ADMIN_URL%]js/bootstrap.js"></script>
		<script type="text/javascript" src="[%ESPCMS_ADMIN_URL%]js/lngpack_cn.js"></script>
		<script type="text/javascript" src="[%ESPCMS_ADMIN_URL%]js/espcms_form.js"></script>
		<script type="text/javascript" src="[%ESPCMS_ADMIN_URL%]js/espcms_formvalidation.js"></script>
		<script type="text/javascript" src="[%ESPCMS_ADMIN_URL%]js/espcms_dialog.js"></script>
		<script type="text/javascript" src="[%ESPCMS_ADMIN_URL%]js/espcms_function.js"></script>
		<script type="text/javascript" src="[%ESPCMS_ADMIN_URL%]js/espcms_page.js"></script>
		<script type="text/javascript" src="[%ESPCMS_ADMIN_URL%]js/espcms_select.js"></script>
		<script type="text/javascript" src="[%ESPCMS_ADMIN_URL%]js/espcms_checkbox.js"></script>
		<script type="text/javascript" src="[%ESPCMS_ADMIN_URL%]js/espcms_select_checkbox.js"></script>
		<script type="text/javascript" src="[%ESPCMS_ADMIN_URL%]js/espcms_batch.js"></script>
		<script type="text/javascript" src="[%ESPCMS_ADMIN_URL%]js/espcms_tab.js"></script>
		<script type="text/javascript" src="[%$ESPCMS_ADMIN_TEMPLATES_URL%]create/create.js"></script>
		<script type="text/javascript">
			$(document).ready(function () {
				banpageKey();
				$('.espcms_save_cancel').unbind('click').bind('click', function () {
					parent.closeifram();
				});

				create_doc_num();
			});

			function create_doc_num() {
				var createrang = '[%$createrang%]';
				if (createrang === '0') {
					create_type_num();
					return false;
				}
				$('#loading').empty().append('[%pack:create_pack-espcms_create_numloading%]').fadeIn("slow");
				$.ajax({
					type: "post", url: "[%$doc_link.count%]", data: {'lng': '[%$lng%]', 'createtime': '[%$createtime%]'}, global: false, dataType: 'json',
					success: function (data) {
						if (data.num == 0) {
							create_type_num();
							return false;
						}
						$('#loading').hide();
						$('#return_num').empty().append(data.message).show();
						$('#return_num').show("slow");
						$('#progress').fadeIn("slow");

						var valuemin = 100 / data.num;
						valuemin = valuemin.toFixed(2);
						create_doc(0, data.num, valuemin);
					}
				});
			}

			function create_doc(limit_num, create_num, valuemin) {
				if (limit_num >= create_num) {
					hiden_progressbar();
					create_type_num();
					return false;
				}
				$.ajax({
					type: "post", url: "[%$doc_link.save%]", data: {lng: '[%$lng%]', createtime: '[%$createtime%]', limit_num: limit_num}, global: false,
					success: function (data) {

						limit_num = limit_num + 1;
						create_doc(limit_num, create_num, valuemin);
						var valuenow = Math.round(valuemin * limit_num);
						$('#progress_bar').attr('aria-valuenow', valuenow);
						$('#progress_bar').css('width', valuenow + '%');
						$('#progress_bar').empty().append(valuenow + '%');
					}
				});
			}

			function create_type_num() {
				$('#loading').empty().append('[%pack:create_pack-espcms_create_type_numloading%]').fadeIn("slow");
				$.ajax({
					type: "post", url: "[%$type_link.count%]", data: {lng: '[%$lng%]', createtype: 1}, global: false, dataType: 'json',
					success: function (data) {
						if (data.num == 0 || !data.tid) {
							create_special_num
							return false;
						}
						$('#loading').hide();
						$('#return_num').empty().append(data.message).show();
						$('#return_num').show("slow");
						$('#progress').fadeIn("slow");

						var valuemin = 100 / data.num;
						valuemin = valuemin.toFixed(2);
						create_type(0, data.tid, valuemin);
					}
				});
			}

			function create_type(limit_num, tid_list, valuemin) {

				var tid_array = tid_list.split('_');
				if (tid_array.length > 0) {
					var tid = tid_array[0];
					$.ajax({
						type: "post", url: "[%$type_link.save%]", data: {lng: '[%$lng%]', tid: tid}, global: false,
						success: function (data) {
							limit_num = limit_num + 1;
							var valuenow = Math.round(valuemin * limit_num);
							$('#progress_bar').attr('aria-valuenow', valuenow);
							$('#progress_bar').css('width', valuenow + '%');
							$('#progress_bar').empty().append(valuenow + '%');
							tid_array.remove(tid);
							if (tid_array.length > 0) {
								tid_list = tid_array.join('_');
								create_type(limit_num, tid_list, valuemin);
							} else {
								hiden_progressbar();
								create_special_num();
								return false;
							}
						}
					});
				} else {
					hiden_progressbar();
					create_special_num();
					return false;
				}

			}

			function create_special_num() {
				$('#loading').empty().append('[%pack:create_pack-espcms_create_special_numloading%]').fadeIn("slow");
				$.ajax({
					type: "post", url: "[%$sub_link.count%]", data: {'lng': '[%$lng%]'}, global: false, dataType: 'json',
					success: function (data) {
						if (data.num == 0 || !data.sid) {
							creat_index();
							return false;
						}
						$('#loading').hide();
						$('#return_num').empty().append(data.message).show();
						$('#return_num').show("slow");
						$('#progress').fadeIn("slow");

						var valuemin = 100 / data.num;
						valuemin = valuemin.toFixed(2);
						create_special(0, data.sid, valuemin);
					}
				});
			}

			function create_special(limit_num, sid_list, valuemin) {

				var sid_array = sid_list.split('_');
				if (sid_array.length > 0) {
					var sid = sid_array[0];
					$.ajax({
						type: "post", url: "[%$sub_link.save%]", data: {lng: '[%$lng%]', sid: sid}, global: false,
						success: function (data) {
							limit_num = limit_num + 1;
							var valuenow = Math.round(valuemin * limit_num);
							$('#progress_bar').attr('aria-valuenow', valuenow);
							$('#progress_bar').css('width', valuenow + '%');
							$('#progress_bar').empty().append(valuenow + '%');
							sid_array.remove(sid);
							if (sid_array.length > 0) {
								sid_list = sid_array.join('_');
								create_special(limit_num, sid_list, valuemin);
							} else {
								creat_index();
								return false;
							}
						}
					});
				} else {
					creat_index();
					return false;
				}

			}

			function creat_index() {
				$('#loading').empty().append('[%pack:create_pack-espcms_create_index_str%]');
				$.ajax({
					type: "post", url: "[%$home_link.save%]", data: {lng: '[%$lng%]'}, global: false,
					success: function (data) {
						parent.$.espcms_sticky('[%pack:create_pack-espcms_create_batch_save_ok_message%]', {'autoclose': 3000});
						parent.closeifram();
						return false;
					}
				});
			}
			function hiden_progressbar() {
				$('#progress').hide();
				$('#progress_bar').attr('aria-valuenow', 0);
				$('#progress_bar').css('width', '0%');
				$('#progress_bar').empty().append('0%');
				$('#loading').hide();
				$('#return_num').hide();
			}
		</script>
	</head>

	<body class="espcms_style_all">
		<div class="main">
			<div class="espcms_center_content_window vt">
				<div class="panel">
					<div class="col-md-12 center mb10 mt15 displaynone" id="loading"></div>
					<div class="col-md-12 center mb10 mt15 displaynone" id="return_num"></div>
					<div class="progress displaynone" id="progress">
						<div class="progress-bar progress-bar-info" id="progress_bar"  role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100"></div>
					</div>
					<div class="form_button">
						<button type="button" class="btn btn-lightgray min-w-150 espcms_save_cancel">[%pack:botton_pack-espcms_botton_create_cancel%]</button>
					</div>
				</div>
			</div>
		</div>
	</body>
</html>
